package com.neusoft.elm.service.impl;
import java.util.ArrayList;
import java.util.List;
import com.neusoft.elm.dao.BusinessDao;
import com.neusoft.elm.dao.FoodDao;
import com.neusoft.elm.dao.impl.BusinessDaoImpl;
import com.neusoft.elm.dao.impl.FoodDaoImpl;
import com.neusoft.elm.po.Business;
import com.neusoft.elm.po.Food;
import com.neusoft.elm.service.FoodService;
import com.neusoft.elm.util.DBUtil;
public class FoodServiceImpl implements FoodService{
 @Override
 public List<Food> listFoodByBusinessId(Integer businessId) {
 List<Food> list = new ArrayList<>();
 FoodDao dao = new FoodDaoImpl();
 try {
 DBUtil.getConnection();
 list = dao.listFoodByBusinessId(businessId);
 }catch (Exception e) {
 e.printStackTrace();
 }finally {
 DBUtil.close();
 }
 return list;
 }
 
 @Override
 public Food getFoodById(Integer foodId) {
 Food food = null;
 FoodDao dao = new FoodDaoImpl();
 try {
 DBUtil.getConnection();
 food = dao.getFoodById(foodId);
 }catch (Exception e) {
 e.printStackTrace();
 }finally {
 DBUtil.close();
 }
 return food;
 }
 
 @Override
 public int saveFood(Food food) {
 int result = 0;
 FoodDao dao = new FoodDaoImpl();
 try {
 DBUtil.getConnection();
 result = dao.saveFood(food);
 }catch (Exception e) {
 e.printStackTrace();
 }finally {
 DBUtil.close();
 }
 return result;
 }
 
 @Override
 public int updateFood(Food food) {
 int result = 0;
 FoodDao dao = new FoodDaoImpl();
 try {
 DBUtil.getConnection();
 result = dao.updateFood(food);
 }catch (Exception e) {
 e.printStackTrace();
 }finally {
 DBUtil.close();
 }
 return result;
 }
 
 @Override
 public int removeFood(Integer foodId) {
 int result = 0;
 FoodDao dao = new FoodDaoImpl();
 try {
 DBUtil.getConnection();
 result = dao.removeFood(foodId);
 }catch (Exception e) {
 e.printStackTrace();
 }finally {
 DBUtil.close();
 }
 return result;
 }
}